package com.yunji.base.service;

import com.yunji.base.convert.AgentConvert;
import com.yunji.base.dao.IAgentDao;
import com.yunji.base.dao.IBelongDao;
import com.yunji.base.dto.AgentDTO;
import com.yunji.base.dto.AgentFieldDTO;
import com.yunji.common.model.domain.AgentDO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * @version 1.0
 * @Project: yunji-coffee
 * @Package com.yunji.user.service.impl
 * @FileName AgentSiteServiceImpl.java
 * @Copyright Copyright © 2024 云集互联. All Rights Reserved
 * Company		com
 * @CreateTime 2024-05-28 18:06:50
 * @Description 代理商网点接口实现
 * @Modification Author                    History Time			Version				Description
 * --------------------------------------------------------------------------------
 * HuaAo				2024-04-08 18:06:50		1.0					1.0 Version
 * @since JDK 1.8.0_202
 */
@Service
public class AgentService {
    @Resource
    private IAgentDao agentDao;

    @Resource
    private IBelongDao belongDao;

    public List<AgentDTO> search(Long... ids) {
        List<AgentDO> agents = agentDao.listByIds(Arrays.asList(ids));
        return AgentConvert.domain2dto(agents, belongDao);
    }

    public List<AgentDTO> searchBelong(Long... belongIds) {
        List<AgentDO> agents = agentDao.listByBelongIds(Arrays.asList(belongIds));
        return AgentConvert.domain2dto(agents, belongDao);
    }

    public AgentDTO select(Long id) {
        return AgentConvert.domain2dto(agentDao.getById(id));
    }

    public AgentDTO selectBelong(Long belongId) {
        return AgentConvert.domain2dto(agentDao.getByBelongId(belongId));
    }

    public boolean create(AgentDO agent) {
        return agentDao.save(agent);
    }

    public boolean update(AgentDO agent) {
        return agentDao.updateById(agent);
    }

    public boolean delete(Long... ids) {
        return agentDao.removeByIds(Arrays.asList(ids));
    }

    public List<AgentDO> selectAgentIds() {
        return agentDao.list();
    }

    public List<AgentDTO> listDto() {
        return AgentConvert.domain2dto(selectAgentIds(), belongDao);
    }

    public List<String> searchTableFiled(AgentFieldDTO param) {
        return agentDao.searchTableFiled(param);
    }

    public AgentDTO getById(Long agentId) {
        return AgentConvert.domain2dto(agentDao.getById(agentId));
    }
}
